package com.wxy.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxy.web.model.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author wxy
 * @since 2021-06-13
 */
public interface UserMapper extends BaseMapper<User> {
    @Select("select u.* from user u join user_role ur on u.id = ur.user_id where ur.role_id ='${roleId}' limit ${start},${pageSize}")
    List<User> listByRoleId(@Param("roleId") Integer roleId, @Param("start") Integer start, @Param("pageSize") Integer pageSize);

    @Select("select count(u.id) from user u join user_role ur on u.id = ur.user_id where ur.role_id ='${roleId}'")
    Integer countByRoleId(@Param("roleId") Integer roleId);

    @Select("insert into user_role (user_id,role_id)values(${userId},${roleId})")
    Boolean insertUserRole(@Param("userId")Integer userId,@Param("roleId")Integer roleId);

    @Select("delete from user_role where user_id = ${userId}")
    Integer deleteRoleByUserId(@Param("userId")Integer userId);
}
